#pragma once

#include <linux/page.h>

extern unsigned long paging_init(unsigned long start_mem, unsigned long end_mem);

#define invalidate() \
    __asm__ __volatile__("movl %%cr3, %%eax\n\tmovl %%eax, %%cr3" \
                         : \
                         :)

#define PAGE_OFFSET   ((unsigned long)0xC0000000)

#define __pa(x)       ((unsigned long)(x)-PAGE_OFFSET)
#define __va(x)       (((unsigned long)(x) + PAGE_OFFSET))

#define PAGE_PRESENT  0x001
#define PAGE_RW       0x002
#define PAGE_USER     0x004
#define PAGE_PWT      0x008 /* 486 only - not used currently */
#define PAGE_PCD      0x010 /* 486 only - not used currently */
#define PAGE_ACCESSED 0x020
#define PAGE_DIRTY    0x040
#define PAGE_COW      0x200 /* implemented in software (one of the AVL bits) */

#define PAGE_SHARED   (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
#define PAGE_TABLE    (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)

#define PTRS_PER_PAGE (PAGE_SIZE / sizeof(void *))
